package com.sky.service.impl;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.mapper.DishFlavorMapper;
import com.sky.mapper.DishMapper;
import com.sky.result.PageResult;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @ClassName: DishServiceImpl
 * @Author: zw
 * @Description: 出百万拳，行万里路；
 * @Create 2025/6/19-00:50
 * @Version 1.0
 */
@Service
@Slf4j
public class DishServiceImpl implements DishService {
    @Autowired
    private DishMapper dishMapper;
    @Autowired
    private DishFlavorMapper dishFlavorMapper;
    @Override
    public void saveWithFlavor(DishDTO dishDTO) {


        Dish dish = new Dish();
        BeanUtils.copyProperties(dishDTO, dish);
        log.info("dish:{}", dish);
        // 1. 首先插入菜品表
        dishMapper.insert(dish);
        // 这里插入到sql以后要重写获取insert语句生成的主键值
        // 2重点这里一定要重写去用getId（）方式去获取到自增的id
        Long dishId = dish.getId();
        // 循环插入数据吗；
        List<DishFlavor> flavorsList = dishDTO.getFlavors();
        if (flavorsList != null && flavorsList.size() > 0) {
            // 3. 拿到新增的菜品表id去给口味数据循环设置逻辑外键id
            flavorsList.forEach(dishFlavor -> dishFlavor.setDishId(dishId));
            // 这里利用集合的方式插入，不是利用for循环插入
            dishFlavorMapper.insertBatch(flavorsList);
        }

    }

    @Override
    public PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO) {
        return null;
    }

    @Override
    public void deleteBatch(List<Long> ids) {

    }

    @Override
    public DishVO getByIdWithFlavor(Long id) {
        return null;
    }

    @Override
    public void updateWithFlavor(DishDTO dishDTO) {

    }

    @Override
    public List<Dish> list(Long categoryId) {
        return null;
    }

    @Override
    public List<DishVO> listWithFlavor(Dish dish) {
        return null;
    }

    @Override
    public void startOrStop(Integer status, Long id) {

    }
}
